<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <style>
        thead tr th{text-align: center!important;}
        tr td{text-align: center!important;}
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">代理姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" autocomplete="off" class="layui-input" placeholder="请输入代理姓名">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">代理账号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="login" autocomplete="off" class="layui-input" placeholder="请输入代理账号">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">代理等级</label>
                            <div class="layui-input-inline">
                                <select name="level">
                                    <option value="">请选择等级</option>
                                    <c:forEach items="${agentList}" var="a">
                                        <option value="${a.id}">${a.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            </button>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layui-btn-warm edit" data-type="edit">添加代理</button>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body">
                    <table class="layui-table" lay-filter="agent-table" id="agent-table"></table>
                    <script type="text/html" id="table-operate">
                        <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
                        <a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="detail">资金明细</a>
                        <a class="layui-btn layui-btn-sm" lay-event="deleteThis">删除</a>
                        {{# if(d.status == 1){ }}
                        <a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="updateThis" data-type="2">通过</a>
                        <a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="updateThis" data-type="3">驳回</a>
                        {{# } }}
                        {{# if(d.status == 2){ }}
                        <a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="updateThis" data-type="4">过期</a>
                        {{# } }}
                        {{# if(d.status == 4){ }}
                        <a class="layui-btn layui-btn-sm layui-btn-primary" lay-event="updateThis" data-type="2">有效</a>
                        {{# } }}
                    </script>
                    <script type="text/html" id="status">
                        {{# if(d.status == 1){ }}
                        <span class="layui-badge">申请中</span>
                        {{# } else if(d.status=== 2) { }}
                        <span class="layui-badge layui-bg-green">已通过</span>
                        {{# } else if(d.status=== 3) { }}
                        <span class="layui-badge">已驳回</span>
                        {{# } else if(d.status=== 4) { }}
                        <span class="layui-badge">已过期</span>
                        {{# } }}
                    </script>
                    <script type="text/html" id="bind">
                        {{# if(d.cid == null){ }}
                        <span class="layui-badge">否</span>
                        {{# } else { }}
                        <span class="layui-badge layui-bg-green">是</span>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form','table'], function(){
        var form = layui.form,table = layui.table,$ = layui.$,admin=layui.admin;

        table.render({
            elem:'#agent-table',
            url:'/agent/queryAgent',
            page:true,
            // toolbar: '#table-operate-tool',
            request:{
                pageName:'current',
                limitName:'size'
            },
            cols:[[
                {field:'id',title:'ID',width:80},
                {field:'login',title:'登录名',minWidth:80},
                {field:'name',title:'姓名',minWidth:100},
                {field:'status',title:'状态',minWidth:100},
                // {field:'donate',title:'贡献值',minWidth:90},
                // {field:'share',title:'共享值',minWidth:100},
                {field:'money',title:'余额',minWidth:100},
                {field:'sumCash',title:'总提现金额',minWidth:100},
                {field:'addressExt',title:'地址',minWidth:200},
                {field:'levelName',title:'代理等级',width:90},
                {field:'status',title:'状态',minWidth:50,templet:"#status"},
                {field:'cid',title:'绑定用户',minWidth:50,templet:"#bind"},
                {field:'createTime',title:'创建时间',minWidth:170,templet:"<div>{{layui.util.toDateString(d.createTime,'yyyy-MM-dd HH:mm:ss')}}</div>"},
                {width:400,title:'操作',align:'center',fixed:'right',toolbar:'#table-operate'}
            ]]
        });

        table.on('tool(agent-table)',function(obj){
            var data = obj.data;
            var event = obj.event;
            if(event === 'edit'){
                layer.open({
                    title:'新增代理',
                    type: 2,
                    area: ['600px', '500px'],
                    content: '/agent/agentEdit?id=' + data.id
                });
            }else if(event === 'deleteThis'){
                layer.confirm('确定操作吗？', function(){
                    admin.req({
                        url: '/agent/deleteAgent',
                        data: {"id":data.id},
                        done: function(res){
                            if(res.status){
                                layer.msg(res.desc, {icon: 1});
                                setTimeout(function () {
                                    table.reload('agent-table');
                                }, 1000)
                            }else{
                                layer.msg(res.desc,{icon:2});
                            }
                        }
                    });
                });
            }else if(event === 'updateThis'){
                var status = $(this).data('type');
                layer.confirm('确定操作吗？', function(){
                    admin.req({
                        url: '/agent/handleUpdateStatus',
                        data: {"id":data.id,"status":status},
                        done: function(res){
                            if(res.status){
                                layer.msg(res.desc, {icon: 1});
                                setTimeout(function () {
                                    table.reload('agent-table');
                                }, 1000)
                            }else{
                                layer.msg(res.desc,{icon:2});
                            }
                        }
                    });
                });
            } else if(event === 'detail'){
                window.location.href = "/agent/accountDetail?agid=" + data.id;
            }
        });


        $('.edit').on('click', function(){
            layer.open({
                title:'新增代理',
                type: 2,
                area: ['600px', '500px'],
                content: '/agent/agentEdit'
            });
        });


        form.on('submit(LAY-app-contlist-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('agent-table', {
                where: field
            });
        });
    });
</script>
</body>
</html>